package com.wframe.project.jnd.wx.wxImpl;

import java.util.Date;

import org.apache.commons.lang.StringUtils;

import com.sun.org.apache.bcel.internal.generic.NEW;



public class AccessTokenSession {

    private static Date lastTime;
    private static String accessToken;
    private static String jsticket;
    
    public static String getAccessToken() throws Exception{
        if(accessToken==null){
            lastTime=new Date();
            accessToken=new WeixInterfaceImpl().getAccessToken();
        }else{
            if(!checkTime()){
                lastTime=new Date();
                accessToken=new WeixInterfaceImpl().getAccessToken();
            }
        }
        return accessToken;
    }
    
    private static boolean checkTime(){
    	if(lastTime==null)return false;
    	 long l=new Date().getTime()-lastTime.getTime();
         long max=1000*60*100;//一百分钟
         if(l>max)
        	 return false;
         else return true;
    }
    
    public static String getJsTicket() throws Exception{
    	if(StringUtils.isBlank(jsticket) || !checkTime()){
    		jsticket=new WeixInterfaceImpl().getJsTicket();
    	}
    	return jsticket;
    }
}
